<template>
  <div class="AddUserHelp">

    <el-dialog title="转送标本" :visible.sync="dialogVisible" :center="isCenter" width="500px">
      <el-form :model="dataForm" ref="dataForm" :rules="roleRules">
        <el-form-item label="收样员：" prop="syUserId" label-width="150px">
          <el-select v-model="dataForm.syUserId" placeholder="请选择收样员">
            <el-option
              v-for="item in pickSyUserList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注：" prop="remark" label-width="150px">
          <el-input type="textarea" v-model="dataForm.remark" autocomplete="off" style="width: 250px"></el-input>
        </el-form-item>
        <el-form-item align="center">
          <el-button @click.native="clickCancel">取 消</el-button>
          <el-button type="primary" @click.native="clickCommit">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  import * as message from "@/constants/message";
  import AuthApi from "@/api/system/auth";
  import CollectApi from "@/api/collect/collect";

  export default {
    name: 'TransferReport',
    props: {
      rcuIdList: {
        type: Array,
        default: []
      },
      curSyUserId: {
        type: Number,
        default: null
      }
    },
    created() {
      this.listSyUser()
      //this.dataForm.relationId = this.props.relationId
    },
    watch:{
      rcuIdList(value) {
        this.dataForm.rcuIdList = value
      },
      curSyUserId(value) {
        this.oldSyUserId = value
      }
    },
    data() {
      return {
        dataForm:{
          rcuIdList:[],
          syUserId:"",
          remark:""
        },
        oldSyUserId: null,
        pickSyUserList: [],
        dialogVisible: false,
        isCenter: true,
        roleRules: {
          syUserId:[
            { required: true, message: "请选择收样员", trigger: "change" }
          ]
          /*content: [
            { required: true, message: "请输入备注", trigger: "blur" },
            { max: 200, message: '内容长度不超过200个字', trigger: 'blur' }
          ],*/
        }
      }
    },
    methods: {
      listSyUser () {
        let _this = this
        AuthApi.listAdminByRole({roleId: 4})
         .then(res => {
          setTimeout(() => {
            let userList = res.data
            let list = userList.filter(item => {
              return item.userId !== _this.oldSyUserId
            })
            _this.pickSyUserList = list.map(item => {
              return {
                value: item.userId,
                label: item.userName
              }
            })
          }, 200)
        })
      },
      clickCancel(){
        this.dialogVisible = false;
        this.dataForm.rcuIdList=[];
        this.dataForm.syUserId="";
        this.dataForm.remark="";
      },
      clickCommit() {
        this.$refs.dataForm.validate(valid => {
          if (valid) {
            this.addData();
           /* this.$confirm(message.MSG_CONFIRM_SAVE_ALTER, message.TITLE_PROMPT, {})
              .then(() => {
              });*/
          }
        })
      },
      addData(){
        let _this = this;
        CollectApi.reportCollectAddTransfer(this.dataForm)
          .then((res) =>{
            _this.dialogVisible = false;
            _this.$Utils.notifySuccess()
            this.$emit('reloadPage')
          });
      },
      handleCreate() {
        this.dialogVisible = true
      }

    }
  }
</script>
<style lang="scss">
  .variant-input {
    margin-top: 2px
  }

  .AddUserHelp .country_ul {
    position: relative;
  }

  .country_ul .country_tabs {
    float: left;
    margin-bottom: 0;
    padding-left: 0;
    list-style: none;
    margin-bottom: -4px;
  }

  .country_ul .country_tabs li {
    float: left;
    cursor: pointer;
    background-color: #eee;
    width: 60px;
    height: 35px;
    margin-right: 5px;
    border: 1px solid #ddd;
    border-radius: 6px;
  }

  .country_ul .country_tabs .active {
    background-color: #fff;
  }

  .country_ul .country_tabs li a {
    span {
      line-height: 30px;
      margin-left: 15px;
    }
  }

  .variant_btn {
    display: flex;
    justify-content: center;
    margin-top: 10px;
  }
</style>
